﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Kingdee.BOS.Util;
using Kingdee.BOS.Core;
using Kingdee.BOS.Core.Bill.PlugIn;
using Kingdee.BOS.Core.DynamicForm.PlugIn;
using Kingdee.BOS.Core.DynamicForm;
using Kingdee.BOS.Core.Metadata.FieldElement;
using Kingdee.BOS.Core.Metadata.StateTracker;
using Kingdee.BOS.Orm.DataEntity;
using Kingdee.BOS.ServiceHelper;
using Kingdee.BOS.Core.Metadata;
using Kingdee.BOS.Core.Bill;
using Kingdee.BOS.Orm;
using Kingdee.BOS.Orm.Metadata.DataEntity;
using Kingdee.BOS.Core.Metadata.EntityElement;
using Kingdee.BOS.Core.DynamicForm.PlugIn.ControlModel;
using Kingdee.BOS.JSON;
using Kingdee.BOS.Core.Const;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args;
using Kingdee.BOS.Core.Metadata.BarElement;
using Kingdee.BOS.Core.SqlBuilder;
using Kingdee.BOS.Core.DynamicForm.PlugIn.Args.UnitTest;
using Kingdee.BOS;
using Kingdee.BOS.Contracts;
using System.Data;
using Kingdee.BOS.App.Data;
using Kingdee.BOS.Core.Interaction;
using Kingdee.BOS.Core.Metadata.ControlElement;

namespace Sincetech.K3.SCM.Common
{
    /// <summary>
    /// 双数明细：单据插件
    /// </summary>
    public class PairDetail_Bill : AbstractDynamicFormPlugIn
    {
        //自定义参数接收的物料编码
        object FMaterialId = null; //物料id
        object F_st_MaterialNo = null;//物料id
        object F_st_RowNo = null; //父单据中的行号
        object OSubEntity = null; //将子单据体-双数明细的对象传递到子窗体中，与PsubEntityRows一起使用
        object PtotalNum = null; //总双数
        DynamicObjectCollection PsubEntityRows = null;//父单据体的子单据体对象

        #region PreOpenForm-单据加载前事件
        /// <summary>
        /// 单据加载前事件
        /// </summary>
        /// <param name="e"></param>
        public override void PreOpenForm(PreOpenFormEventArgs e)
        {
            base.PreOpenForm(e);
            #region
            FMaterialId = e.OpenParameter.GetCustomParameter("FMATERIALID");
            F_st_MaterialNo = e.OpenParameter.GetCustomParameter("F_st_MaterialNo");
            F_st_RowNo = e.OpenParameter.GetCustomParameter("F_st_RowNo");
            OSubEntity = e.OpenParameter.GetCustomParameter("SubEntityRows");
            PsubEntityRows = (DynamicObjectCollection)OSubEntity;
            PtotalNum = e.OpenParameter.GetCustomParameter("PtotalNum");
            #endregion
        }
        #endregion

        /// <summary>
        /// 设置逻辑元模型,通过相应的物料编码，获取相应的尺码组，设置逻辑
        /// </summary>
        /// <param name="e"></param>
        //        public override void OnSetBusinessInfo(SetBusinessInfoArgs e)
        //        {
        //            // 创建当前单据元数据副本，避免直接修改原始元数据，并发时串账
        //            FormMetadata currmetadata = (FormMetadata)ObjectUtils.CreateCopy(
        //                                       this.View.OpenParameter.FormMetaData);
        //            BusinessInfo _currBusinessInfo = currmetadata.BusinessInfo;
        //            LayoutInfo _currLayoutInfo = currmetadata.GetLayoutInfo();

        //            // 取物料明细单据体的元数据模型
        //            string currEntityKey = "FEntity";
        //            var currEntity = _currBusinessInfo.GetEntity(currEntityKey);

        //            // 修改明细单据体采用的表格名称，指向进行了行列转换，包含了各个尺码的视图
        //            //currEntity.TableName = "v_Cust_JDDynamicColumnEntry"; 

        //            string sql = string.Format(@"SELECT  t.FDATAVALUE
        //FROM    T_BAS_ASSISTANTDATAENTRY_L t
        //WHERE   t.FENTRYID IN (
        //        SELECT  t1.F_ST_SIZE
        //        FROM    st_t_Cust_SizeGroupEntry t1
        //        WHERE   t1.FID IN ( SELECT  t2.F_ST_SIZEGROUP
        //                            FROM    T_BD_MATERIAL t2
        //                            WHERE   t2.FMATERIALID = {0} ) )", FMaterialId);

        //            //Dictionary<long, long> idInfos = new Dictionary<long, long>();
        //            List<string> idInfos = new List<string>();
        //            int i = 0;
        //            using (IDataReader dr = DBUtils.ExecuteReader(this.Context, sql))
        //            {
        //                while (dr.Read())
        //                {
        //                    idInfos.Add(Convert.ToString(dr["FDATAVALUE"]));
        //                    i++;
        //                }
        //                dr.Close();
        //            }
        //            if (idInfos.Count < 1)
        //            {
        //                return;
        //            }

        //            int j = 1;
        //            //循环添加尺码进逻辑元数据模型中（即单据体中）
        //            foreach (string Size in idInfos)
        //            {
        //                string qtyString = "F_YFG_Qty" + j.ToString();

        //                //获取

        //                //FieldAppearance qtyFldApp = _currLayoutInfo.GetFieldAppearance(qtyString);

        //                //Field size1Field = (Field)ObjectUtils.CreateCopy(qtyField);
        //                //this.View.BusinessInfo.GetField(qtyString).DynamicProperty = null;
        //                //this.View.BusinessInfo.GetField(qtyString).ChildrenFields.Clear();
        //                //this.View.BusinessInfo.GetField(qtyString).EntityKey = currEntityKey;
        //                //this.View.BusinessInfo.GetField(qtyString).Entity = currEntity;
        //                //if (this.View.BusinessInfo.GetField(qtyString).UpdateActions != null)
        //                //{
        //                //    this.View.BusinessInfo.GetField(qtyString).UpdateActions.Clear();
        //                //}
        //                //// 必改属性，涉及到数据的加载
        //                //this.View.BusinessInfo.GetField(qtyString).Key = Size;
        //                //this.View.BusinessInfo.GetField(qtyString).FieldName = Size;
        //                //this.View.BusinessInfo.GetField(qtyString).PropertyName = Size;
        //                //this.View.BusinessInfo.GetField(qtyString).Name = new LocaleValue(Size);
        //                this.View.LayoutInfo.GetAppearance(qtyString).Caption = new LocaleValue(Size);
        //                this.View.LayoutInfo.GetAppearance(qtyString).VisibleExt = Size;
        //                //this.View.LayoutInfo.GetAppearance(qtyString).
        //                //this.View.GetFieldEditor(this.View.LayoutInfo.GetAppearance(qtyString),0)
        //                // 把FSize1字段，添加到单据的逻辑元数据模型(BusinessInfo)中
        //                //_currBusinessInfo.Add(size1Field);
        //                j++;
        //            }
        //        }


        // <summary>
        // 给尺码列赋值
        // </summary>
        // <param name="e"></param>
        //public override void CreateNewData(BizDataEventArgs e)
        //{
        //    base.CreateNewData(e);
        //    this.View.UpdateView("FEntity");
        //    Entity subEntity = this.View.BillBusinessInfo.GetEntity("FEntity");
        //    if (subEntity.IsNullOrEmpty()) { }
        //    else
        //    {
        //        DynamicObjectCollection EntityRows = this.View.Model.GetEntityDataObject(subEntity);
        //        //删除双数明细的全部行
        //        EntityRows.Clear();
        //    }


        //    for (int k = 0; k < PsubEntityRows.Count; k++)
        //    {
        //        // 通过复制对象的方式，复制新行 (using Kingdee.BOS.Orm;)
        //        DynamicObject newEntryRow = (DynamicObject)PsubEntityRows[k].Clone(false, true);
        //        // 把新行添加新单据上
        //        //int iRow = View.Model.GetEntryCurrentRowIndex("FEntity");
        //        View.Model.CreateNewEntryRow("FEntity");
        //        View.Model.SetValue("F_st_LR", newEntryRow["F_ST_LR"], k);
        //        View.Model.SetValue("F_st_SIZE", newEntryRow["F_ST_SIZE"], k);
        //        View.Model.SetValue("F_st_Qty", newEntryRow["F_ST_PAIRDETAILQTY"], k);
        //        //this.Model.CreateNewEntryRow(subEntity, k, newEntryRow);
        //    }
        //    this.View.UpdateView("FEntity");
        //}

        #region AfterBindData-控件绑定数据后触发事件
        /// <summary>
        /// 控件绑定数据后触发事件
        /// </summary>
        /// <param name="e"></param>
        public override void AfterBindData(EventArgs e)
        {
            // 创建本界面需要的数据对象
            //e.BizDataObject = new DynamicObject(this.View.OpenParameter.FormMetaData.BusinessInfo.GetDynamicObjectType());
            string sql = string.Format(@"SELECT  t.FENTRYID
FROM    T_BAS_ASSISTANTDATAENTRY_L t
WHERE   t.FENTRYID IN (
        SELECT  t1.F_ST_SIZE
        FROM    st_t_Cust_SizeGroupEntry t1
        WHERE   t1.FID IN ( SELECT  t2.F_ST_SIZEGROUP
                            FROM    T_BD_MATERIAL t2
                            WHERE   t2.FMATERIALID = {0} ) )", FMaterialId);

            //Dictionary<long, long> idInfos = new Dictionary<long, long>();

            //idInfos存储的是尺码的内码
            List<string> idInfos = new List<string>();
            int i = 0;
            using (IDataReader dr = DBUtils.ExecuteReader(this.Context, sql))
            {
                while (dr.Read())
                {
                    idInfos.Add(Convert.ToString(dr["FENTRYID"]));
                    i++;
                }
                dr.Close();
            }

            DynamicObject[] objs = BusinessDataServiceHelper.Load(
                this.Context,
                new object[] { FMaterialId },
                (MetaDataServiceHelper.Load(this.Context, "BD_Material") as FormMetadata).
                BusinessInfo.GetDynamicObjectType());


            Entity subEntity = this.View.BillBusinessInfo.GetEntity("FEntity");
            DynamicObjectCollection subEntityRows = this.View.Model.GetEntityDataObject(subEntity);
            if (subEntity.IsNullOrEmpty()) { }
            else
            {
                //删除双数明细的全部行
                subEntityRows.Clear();
            }

            if (PsubEntityRows.Count > 1)
            {
                for (int k = 0; k < PsubEntityRows.Count; k++)
                {
                    // 通过复制对象的方式，复制新行 (using Kingdee.BOS.Orm;)
                    DynamicObject newEntryRow = (DynamicObject)PsubEntityRows[k].Clone(false, true);
                    // 把新行添加新单据上
                    //int iRow = View.Model.GetEntryCurrentRowIndex("FEntity");
                    View.Model.CreateNewEntryRow("FEntity");
                    View.Model.SetValue("F_st_LR", newEntryRow["F_ST_LR"], k);
                    View.Model.SetValue("F_st_SIZE", newEntryRow["F_ST_SIZE"], k);
                    View.Model.SetValue("F_st_Qty", newEntryRow["F_ST_PAIRDETAILQTY"], k);
                    //this.Model.CreateNewEntryRow(subEntity, k, newEntryRow);
                }
                this.View.UpdateView("FEntity");
                BusinessInfo info = this.View.OpenParameter.FormMetaData.BusinessInfo;

                Entity resultEntity = info.GetEntity("FEntity");


            }
            else
            {

                //this.View.Model.DeleteEntryData("FEntity");
                for (int j = 0; j < idInfos.Count; j++)
                {
                    View.Model.CreateNewEntryRow("FEntity");
                    int iRow = View.Model.GetEntryCurrentRowIndex("FEntity");
                    View.Model.SetValue("F_st_Size", idInfos[j], iRow);
                }
            }

            //单据头赋值
            View.Model.SetValue("F_st_MaterialNo", objs[0]);
            this.View.UpdateView("F_st_MaterialNo");
            this.View.UpdateView("F_st_MaterialName");
            //View.Model.SetValue("F_st_MaterialName", "");
            View.Model.SetValue("F_st_RowNo", F_st_RowNo);
            this.View.UpdateView("F_st_RowNo");
            View.Model.SetValue("F_st_QtySum", PtotalNum);
            this.View.UpdateView("F_st_QtySum");
            //View.Model.SetValue("F_st_QtySum", "");

            //更新单据体
            this.View.UpdateView("FEntity");

            //尺码字段，辅助属性
            //Field sizeField = info.GetField("F_st_Size");

            //DynamicObjectCollection resultEntityData = (DynamicObjectCollection)resultEntity.DynamicProperty.GetValue(e.BizDataObject);



            //DynamicObjectCollection subEntityRows = this.View.Model.GetEntityDataObject(subEntity);
            ////删除双数明细的全部行
            //subEntityRows.Clear();
            //this.View.Model.DeleteEntryData("FEntity");
            //for (int j = 0; j < idInfos.Count; j++)
            //{
            //    View.Model.CreateNewEntryRow("FEntity");
            //    int iRow = View.Model.GetEntryCurrentRowIndex("FEntity");
            //    View.Model.SetValue("F_st_Size", idInfos[j], iRow);
            //    View.Model.SetValue("F_st_LR", "L", iRow);
            //DynamicObjectCollection collecions =
            //    this.View.Model.GetEntityDataObject(resultEntity);
            //DynamicObject obj = collecions[j];
            //obj["F_st_Size"] = idInfos[j];
            //this.View.Model.CreateNewEntryRow("FEntity");

            //获取单据体元数据

            //EntryEntity entry = this.View.BillBusinessInfo.GetEntryEntity("FEntity");

            //获取指定一行的单据体数据

            //DynamicObject entity_obj = this.Model.GetEntityDataObject(entry, j);

            //获取子单据体元数据

            //SubEntryEntity sub_entry = this.View.BillBusinessInfo.GetEntryEntity("FSubEntry") as SubEntryEntity;

            //创建新的子单据体分录行

            //this.Model.CreateNewEntryRow(entity_obj, sub_entry, 0);

            ////添加新行
            //DynamicObject rowData = new DynamicObject(resultEntity.DynamicObjectType);

            //获取基础资料字段元数据描述信息
            //BaseDataField baseDataField = this.View.BusinessInfo.GetField("F_st_Size") as BaseDataField;

            //获取辅助资料字段元数据描述信息
            //AssistantField AssistantDataField = this.View.BusinessInfo.GetField("F_st_Size") as AssistantField;
            //rowData["F_st_Size"] = new DynamicObject(sizeField.DynamicProperty.ReflectedType);
            //给行赋予辅助属性字段
            //AssistantDataField.RefIDDynamicProperty.SetValue(rowData, idInfos[j]);
            //DynamicObject sizeObj = Kingdee.BOS.ServiceHelper.BusinessDataServiceHelper.LoadSingle(this.View.Context, idInfos[0], AssistantDataField.RefFormDynamicObjectType);
            //AssistantDataField.DynamicProperty.SetValue(rowData, sizeObj);

            //DynamicObject sizeObj=BusinessDataServiceHelper.LoadSingle(this.Context,)

            //baseDataField.RefIDDynamicProperty.SetValue(rowData,)

            //给行中字段赋值
            //sizeField.DynamicProperty.SetValue(rowData, idInfos[j]);

            //this.View.Model.SetItemValueByNumber();

            //给表格添加行
            //resultEntityData.Add(rowData);
            //}

            //更新单据体
            //this.View.UpdateView("FEntity");
        }
        #endregion

        #region BeforeClosed-关闭时返回数据
        /// <summary>
        /// 关闭时返回数据
        /// </summary>
        /// <param name="e"></param>
        public override void BeforeClosed(BeforeClosedEventArgs e)
        {
            Entity entity = this.View.BusinessInfo.GetEntity("FEntity");
            DynamicObjectCollection objs = this.View.Model.GetEntityDataObject(entity);
            objs.Clear();
            FMaterialId = null;
            F_st_MaterialNo = null;
            F_st_RowNo = null;
            OSubEntity = null;
            PsubEntityRows = null;
            PtotalNum = null;
        }
        #endregion

        #region DataChanged-值更新事件
        /// <summary>
        /// 值更新事件
        /// </summary>
        /// <param name="e"></param>
        public override void DataChanged(DataChangedEventArgs e)
        {
            #region 下拉框值更新事件
            if (e.Field.Key.ToUpper() == "F_st_HLR".ToUpper())
            {
                if (this.View.Model.GetValue("F_st_HLR").ToString() == "L")
                {
                    BusinessInfo info = this.View.OpenParameter.FormMetaData.BusinessInfo;

                    Entity resultEntity = info.GetEntity("FEntity");

                    string sql = string.Format(@"SELECT  t.FENTRYID
FROM    T_BAS_ASSISTANTDATAENTRY_L t
WHERE   t.FENTRYID IN (
        SELECT  t1.F_ST_SIZE
        FROM    st_t_Cust_SizeGroupEntry t1
        WHERE   t1.FID IN ( SELECT  t2.F_ST_SIZEGROUP
                            FROM    T_BD_MATERIAL t2
                            WHERE   t2.FMATERIALID = {0} ) )", FMaterialId);

                    //Dictionary<long, long> idInfos = new Dictionary<long, long>();

                    //idInfos存储的是尺码的内码
                    List<string> idInfos = new List<string>();
                    int i = 0;
                    using (IDataReader dr = DBUtils.ExecuteReader(this.Context, sql))
                    {
                        while (dr.Read())
                        {
                            idInfos.Add(Convert.ToString(dr["FENTRYID"]));
                            i++;
                        }
                        dr.Close();
                    }

                    //单据头赋值
                    View.Model.SetValue("F_st_MaterialNo", FMaterialId);
                    //View.Model.SetValue("F_st_MaterialName", "");
                    View.Model.SetValue("F_st_RowNo", F_st_RowNo);



                    Entity subEntity = this.View.BillBusinessInfo.GetEntity("FEntity");
                    DynamicObjectCollection subEntityRows = this.View.Model.GetEntityDataObject(subEntity);
                    //删除双数明细的全部行
                    subEntityRows.Clear();
                    //this.View.Model.DeleteEntryData("FEntity");
                    for (int j = 0; j < idInfos.Count; j++)
                    {
                        View.Model.CreateNewEntryRow("FEntity");
                        int iRow = View.Model.GetEntryCurrentRowIndex("FEntity");
                        View.Model.SetValue("F_st_Size", idInfos[j], iRow);
                        View.Model.SetValue("F_st_LR", "L", iRow);
                    }

                    //更新单据体
                    this.View.UpdateView("FEntity");
                }
                if (this.View.Model.GetValue("F_st_HLR").ToString() == "R")
                {
                    BusinessInfo info = this.View.OpenParameter.FormMetaData.BusinessInfo;

                    Entity resultEntity = info.GetEntity("FEntity");

                    string sql = string.Format(@"SELECT  t.FENTRYID
FROM    T_BAS_ASSISTANTDATAENTRY_L t
WHERE   t.FENTRYID IN (
        SELECT  t1.F_ST_SIZE
        FROM    st_t_Cust_SizeGroupEntry t1
        WHERE   t1.FID IN ( SELECT  t2.F_ST_SIZEGROUP
                            FROM    T_BD_MATERIAL t2
                            WHERE   t2.FMATERIALID = {0} ) )", FMaterialId);

                    //Dictionary<long, long> idInfos = new Dictionary<long, long>();

                    //idInfos存储的是尺码的内码
                    List<string> idInfos = new List<string>();
                    int i = 0;
                    using (IDataReader dr = DBUtils.ExecuteReader(this.Context, sql))
                    {
                        while (dr.Read())
                        {
                            idInfos.Add(Convert.ToString(dr["FENTRYID"]));
                            i++;
                        }
                        dr.Close();
                    }

                    //单据头赋值
                    View.Model.SetValue("F_st_MaterialNo", FMaterialId);
                    //View.Model.SetValue("F_st_MaterialName", "");
                    View.Model.SetValue("F_st_RowNo", F_st_RowNo);
                    //View.Model.SetValue("F_st_QtySum", "");
                    Entity subEntity = this.View.BillBusinessInfo.GetEntity("FEntity");
                    DynamicObjectCollection subEntityRows = this.View.Model.GetEntityDataObject(subEntity);
                    //删除双数明细的全部行
                    subEntityRows.Clear();
                    //this.View.Model.DeleteEntryData("FEntity");
                    for (int j = 0; j < idInfos.Count; j++)
                    {
                        View.Model.CreateNewEntryRow("FEntity");
                        int iRow = View.Model.GetEntryCurrentRowIndex("FEntity");
                        View.Model.SetValue("F_st_Size", idInfos[j], iRow);
                        View.Model.SetValue("F_st_LR", "R", iRow);
                    }

                    //更新单据体
                    this.View.UpdateView("FEntity");
                }
                if (this.View.Model.GetValue("F_st_HLR").ToString() == "LR")
                {
                    BusinessInfo info = this.View.OpenParameter.FormMetaData.BusinessInfo;

                    Entity resultEntity = info.GetEntity("FEntity");

                    string sql = string.Format(@"SELECT  t.FENTRYID
FROM    T_BAS_ASSISTANTDATAENTRY_L t
WHERE   t.FENTRYID IN (
        SELECT  t1.F_ST_SIZE
        FROM    st_t_Cust_SizeGroupEntry t1
        WHERE   t1.FID IN ( SELECT  t2.F_ST_SIZEGROUP
                            FROM    T_BD_MATERIAL t2
                            WHERE   t2.FMATERIALID = {0} ) )", FMaterialId);

                    List<string> idInfos = new List<string>();
                    int i = 0;
                    using (IDataReader dr = DBUtils.ExecuteReader(this.Context, sql))
                    {
                        while (dr.Read())
                        {
                            idInfos.Add(Convert.ToString(dr["FENTRYID"]));
                            i++;
                        }
                        dr.Close();
                    }

                    //单据头赋值
                    View.Model.SetValue("F_st_MaterialNo", FMaterialId);
                    //View.Model.SetValue("F_st_MaterialName", "");
                    View.Model.SetValue("F_st_RowNo", F_st_RowNo);
                    //View.Model.SetValue("F_st_QtySum", "");
                    Entity subEntity = this.View.BillBusinessInfo.GetEntity("FEntity");
                    DynamicObjectCollection subEntityRows = this.View.Model.GetEntityDataObject(subEntity);
                    //删除双数明细的全部行
                    subEntityRows.Clear();
                    //this.View.Model.DeleteEntryData("FEntity");
                    for (int j = 0; j < idInfos.Count; j++)
                    {
                        View.Model.CreateNewEntryRow("FEntity");
                        int iRow = View.Model.GetEntryCurrentRowIndex("FEntity");
                        View.Model.SetValue("F_st_Size", idInfos[j], iRow);
                        View.Model.SetValue("F_st_LR", "L", iRow);
                    }
                    for (int j = 0; j < idInfos.Count; j++)
                    {
                        View.Model.CreateNewEntryRow("FEntity");
                        int iRow = View.Model.GetEntryCurrentRowIndex("FEntity");
                        View.Model.SetValue("F_st_Size", idInfos[j], iRow);
                        View.Model.SetValue("F_st_LR", "R", iRow);
                    }
                    //更新单据体
                    this.View.UpdateView("FEntity");
                }

            }
            #endregion

            #region 分录行字段双数值更新事件
            if (e.Field.Key.ToUpper() == "F_st_Qty".ToUpper())
            {
                int TotalNum = 0;
                Entity entity = this.View.BusinessInfo.GetEntity("FEntity");
                DynamicObjectCollection objs = this.View.Model.GetEntityDataObject(entity);
                for (int i = 0; i < objs.Count; i++)
                {
                    int num = Convert.ToInt32(this.Model.GetValue("F_st_Qty", i).ToString());
                    TotalNum += num;
                }
                this.View.Model.SetValue("F_st_QtySum", TotalNum);
            }
            #endregion
        }
        #endregion

        #region BarItemClick-菜单按钮点击事件
        /// <summary>
        /// 菜单点击事件
        /// </summary>
        /// <param name="e"></param>
        public override void BarItemClick(BarItemClickEventArgs e)
        {
            if (e.BarItemKey == "tbSave")
            {
                //this.View.UpdateView("FEntity");
                Entity entity = this.View.BusinessInfo.GetEntity("FEntity");
                DynamicObjectCollection objs = this.View.Model.GetEntityDataObject(entity);
                DynamicObjectCollection objReturn = new DynamicObjectCollection(entity.DynamicObjectType);
                BusinessInfo info = this.View.OpenParameter.FormMetaData.BusinessInfo;
                Field sizeField = info.GetField("F_st_Size");
                Field qtySumField = info.GetField("F_st_QtySum");
                //遍历收款单列表，如果被选中则添加返回数据中
                foreach (DynamicObject dy in objs)
                {
                    objReturn.Add(dy);
                }
                PairDetailRtnData dataReturn = new PairDetailRtnData();
                dataReturn.DynObjCollection = objReturn;
                decimal tNum = (decimal)this.View.Model.GetValue(qtySumField);
                dataReturn.totalNum = (int)tNum;
                dataReturn.rowNum = Convert.ToInt32(F_st_RowNo.ToString()) - 1;
                dataReturn.opType = 1;
                //清空动态表单数据
                objs.Clear();
                FMaterialId = null;
                F_st_MaterialNo = null;
                F_st_RowNo = null;
                OSubEntity = null;
                PsubEntityRows = null;
                PtotalNum = null;
                //将数据返回到父窗体中
                this.View.ReturnToParentWindow(dataReturn);
            }
        }
        #endregion
    }
}
